<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加 - Powered by __CAOZHA-SYS-NAME__ __CAOZHA-SYS-VERSION__</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__CAOZHA-LAYUIMINI__/lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__CAOZHA-LAYUIMINI__/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
    <script src="__CAOZHA-STATIC__/js/jquery-3.4.1.min.js"></script>
    <script src="__CAOZHA-LAYUIMINI__/lib/layui/layui.js" charset="utf-8"></script>
    <script src="__CAOZHA-STATIC__/js/all.js"></script>
    <link rel="stylesheet" href="__CAOZHA-STATIC__/css/style.css" media="all">

    <script type="text/javascript" charset="utf-8" src="__CAOZHA-STATIC__/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="__CAOZHA-STATIC__/ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加载语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="__CAOZHA-STATIC__/ueditor/lang/zh-cn/zh-cn.js"></script>
</head>
<body>
<form class="layui-form layuimini-form">

    <div class="layui-form-item">
        <label class="layui-form-label required">所属分类</label>
        <div class="layui-input-block">
            <select name="catid" style="width:350px;" lay-filter="catid" lay-search="" lay-verify="required" lay-reqtext="请选择分类">
                <option value=""></option>
                {$parentid_select|raw}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" lay-reqtext="请输入标题" placeholder="请输入标题" value=""
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">关键词</label>
        <div class="layui-input-block">
            <input type="text" name="keywords" placeholder="请输入关键词" value=""
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">文章描述</label>
        <div class="layui-input-block">
            <textarea name="description" class="layui-textarea" placeholder=""></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">Tag标签</label>
        <div class="layui-input-block">
            <input type="text" name="tags" placeholder="请输入Tag标签，多个中间用,分隔" value=""
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
    <label class="layui-form-label">缩略图</label>
    <div class="layui-input-block">
        <!--直接调用ueditor上传框-->
        <script type="text/plain" id="upload_ue" style="display: none"></script>
        <script src="__CAOZHA-STATIC__/ueditor/cz.upload.image.js"></script>

        <input type="text" name="thumb" lay-verify="" lay-reqtext="" placeholder="" value="" id="pic_id" class="layui-input cz-float-left" style="width: 50%;margin-right: 10px;"> <button type="button" class="layui-btn layui-btn-normal cz-float-left" onclick="upImage('pic_id');">上传</button> <button type="button" class="layui-btn layui-btn-warm cz-float-left" onclick="img_preview('pic_id');">预览</button>
    </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <textarea name="content" id="editor" placeholder="请输入内容" style="width:100%;height:500px;"></textarea>
            <!-- 实例化编辑器 -->
            <script type="text/javascript">
                var ue = UE.getEditor('editor',{
                    zIndex: "0" //设置层级关系，避免挡住了下拉框
                });
            </script>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">文章状态</label>
        <div class="layui-input-block">
            <select name="status" lay-verify="required" lay-reqtext="请选择文章状态">
                <option value=""></option>
                {foreach $article_status as $key=>$vo }
                <option value="{$key}">{$vo}</option>
                {/foreach}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">排序</label>
        <div class="layui-input-block">
            <input type="text" name="listorder" lay-verify="required" lay-reqtext="请输入排序号，必须数字" placeholder="请输入排序号，必须数字，值越大越靠前" value="0" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">风格</label>
        <div class="layui-input-block">
            <input type="text" name="style" placeholder="" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">外部链接</label>
        <div class="layui-input-block">
            <input type="checkbox" value="1" name="islink" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
            <div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em>是</em><i></i>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">URL</label>
        <div class="layui-input-block">
            <input type="text" name="url" value="" placeholder="设置为外部链接时有效" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">允许评论</label>
        <div class="layui-input-block">
            <input type="checkbox" checked="" value="1" name="iscomment" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
            <div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em>是</em><i></i>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">推荐</label>
        <div class="layui-input-block">
            <input type="checkbox" value="1" name="isreco" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
            <div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em>是</em><i></i>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">热门</label>
        <div class="layui-input-block">
            <input type="checkbox" value="1" name="ishot" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
            <div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em>是</em><i></i>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">置顶</label>
        <div class="layui-input-block">
            <input type="checkbox" value="1" name="istop" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
            <div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em>是</em><i></i>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">作者</label>
        <div class="layui-input-block">
            <input type="text" name="author" placeholder="" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">文章来源</label>
        <div class="layui-input-block">
            <input type="text" name="copyfrom" placeholder="" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">发布时间</label>
        <div class="layui-input-block">
            <input type="text" name="inputtime" lay-reqtext="请选择时间" value="" class="layui-input" id="inputtime" placeholder="yyyy-MM-dd HH:mm:ss">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">浏览数</label>
        <div class="layui-input-block">
            <input type="number" name="hits" lay-verify="required" lay-reqtext="请输入浏览数" placeholder="请输入浏览数" value="0" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" style="display: none">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn caozha-submit" lay-submit="" lay-filter="saveBtn">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary caozha-reset">重置</button>
        </div>
    </div>

</form>
<script>
    layui.use(['form','laydate'], function () {

        var laydate = layui.laydate;
        //日期时间选择器
        laydate.render({
            elem: '#inputtime'
            ,type: 'datetime'
            ,value: new Date()
        });

        var form = layui.form,
            layer = layui.layer;

        layer_skin(layer);

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            $.ajax({
                type: "post",
                url: '{:url(\'admin/article/addSave\')}',
                data: data.field,
                dataType: "json",
                async: false,
                success: function (res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, {icon: 1});
                        setTimeout(function(){
                            // 关闭弹出层
                            //layer.close(index);
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                            parent.location.reload();
                        },800);
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                },
                complete: function (res) {
                }
            });

            return false;
        });

        //解决下拉框出现&nbap乱码
        form.on('select(catid)', function(data){
            let selectText=data.elem[data.elem.selectedIndex].text;//得到被选中的文本值
            selectText=selectText.trim();//去掉&nbap
            data.elem[data.elem.selectedIndex].text=selectText;//覆盖原文本值
        });

    });

</script>
</body>
</html>